<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite ptb20 radius10 pl10 pr20 justify-between">
      <div>
        <el-input v-model="scale" style="width: 280px" placeholder="搜尋等級..." :prefix-icon="Search" class="search" />

      </div>
      <div class="noshrink">
        <el-button class="btn2" @click="search()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">
          <el-table-column prop="scale" label="等級" width="100" />

          <el-table-column prop="scale_name" label="等級名稱" width="120" />
          <el-table-column prop="logo" label="等級Logo" width="200">
            <template #default="scope">
              <el-avatar shape="square" :size="50" :fit="'cover'" :src="scope.row.logo" />
            </template>
          </el-table-column>
          <el-table-column prop="agent_num" label="團隊人數" width="100" />

          <el-table-column prop="performance" label="團隊業績" width="120" />
          <el-table-column prop="introduce" label="團隊權益" width="150" />
          <el-table-column prop="bili" label="抽成比例" width="120" />

          <el-table-column prop="created_at" label="創建時間" min-width="200" />
          <el-table-column prop="updated_at" label="更新時間" min-width="200" />
          <el-table-column prop="" label="操作" width="100" fixed="right">
            <template #default="scope">
              <div class=" pointer" @click="edit(scope.row)">編輯</div>

            </template>
          </el-table-column>

        </el-table>
      </div>
      <div class=" justify-between plr20 w100p mt15">
        <div class="align-center">

          <el-button class="btn2" @click="toAdd()">新增</el-button>
        </div>
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { levelList } from '@/api/brokers'
onMounted(() => {
  getLevelList()
})
const getLevelList = () => {
  levelList({
    page: currentPage.value,
    scale: scale.value
  }).then((res) => {
    console.log('等级列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
  })
}
const scale = ref('')
const dialogTableVisible = ref(false)
const dialogType = ref(1)
const dialogShow = (type) => {
  console.log('dialog----show----')
  dialogType.value = type
  dialogTableVisible.value = true
}

const tableData = ref([])
const tableRowClassName = () => {
  return 'tbrow'
}
const total = ref(0)
const currentPage = ref(1)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
  getLevelList()
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  getLevelList()

}
const search = () => {
  getLevelList()
}
const reset = () => {
  scale.value = ''
  getLevelList()
}
const router = useRouter()
const toAdd = () => {
  console.log(router)
  router.push({ path: 'editBrokerLevel', query: { type: 'add' } })
}
const edit = (row) => {
  router.push({ path: 'editBrokerLevel', query: { ...row, type: 'edit' } })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}
</style>
<style></style>
 